﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using GameEngine.Libs;

namespace GameEngine.Model.Data
{
    public class CameraVO:ICameraVO
    {
        public Point Position{get;set;}
        public int NavigationStep { get; set; }
        public float Scale { get; set; }

        public CameraVO() {
            Position = new Point();
            NavigationStep = 1;
            Scale = 1;
        }

        public virtual string Serialize()
        {
            //return Serializer.Serialize(VO);
            XDocument doc = new XDocument();
            XElement mainNode = new XElement("CameraVO");
            {
                XElement node = new XElement("Position");
                node.Add(new XCData(Serializer.Serialize(Position)));
                mainNode.Add(node);
            }
            {
                XElement node = new XElement("NavigationStep");
                node.Add(new XCData(Serializer.Serialize(NavigationStep)));
                mainNode.Add(node);
            }
            {
                XElement node = new XElement("Scale");
                node.Add(new XCData(Serializer.Serialize(Scale)));
                mainNode.Add(node);
            }
            return mainNode.ToString();
        }

        public virtual void DeSerialize(string serializedString)
        {
            XElement mainNode = XElement.Parse(serializedString);
            foreach (XElement node in mainNode.Nodes())
            {
                switch (node.Name.LocalName)
                {
                    case "Position":
                        {
                            Position = (Point)Serializer.DeSerialize(typeof(Point), node.Value);
                        }
                        break;
                    case "NavigationStep":
                        {
                            NavigationStep = (int)Serializer.DeSerialize(typeof(int), node.Value);
                        }
                        break;
                    case "Scale":
                        {
                            Scale = (float)Serializer.DeSerialize(typeof(float), node.Value);
                        }
                        break;
                }
            }
        }
    }
}
